/* @(#)GSLoginAction.java    
 *
 * Project: BUS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Simonyi Peng 2006-2-16    建立
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;


import system.LoginContext;

import com.hitrust.gs.bean.GSProductUpdateIsbuyBean;
import com.hitrust.gs.dao.GSManufactureDAO;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;

public class GSProductUpdateIsbuyAuditingAction extends GSBaseAction {
	public String execute(GSBaseForm aForm) throws Exception {
		GSManufactureDAO dao = new GSManufactureDAO();
		String indexs = aForm.getRequest().getParameter("indexs");
		String type = aForm.getRequest().getParameter("type");
		String isConfirmOrReject = aForm.getRequest().getParameter(
				"confirmorreject");
		String[] ids=indexs.split(",");
		
		LoginContext context = (LoginContext) aForm.getSession().getAttribute(
				GSBaseConstants.LOGIN);

		for(int i=0;i<ids.length;i++){
			GSProductUpdateIsbuyBean pubean = dao.getProductUpdateIsbuyById(ids[i]," select * from t_product_update_isbuy ");
				if(pubean!=null&&!"0".equals(pubean.getGs_auditing_status())){	
					aForm.getRequest().setAttribute("action","A190014.do?type="+type);					
					throw new GSException(
							"存在审批状态不是待审批的记录!请重新查询!");
				}

		}



		if ("T".equals(isConfirmOrReject)) {
			for(int i=0;i<ids.length;i++){
				dao.updateProductUpdateIsbuy("1",context.getLoginUserId(),context.getLoginUserName(),new framework.core.DateUtil().getFullString(),ids[i]);
			}
			aForm.getRequest().setAttribute("SUCCESSMSG", "审批通过执行成功");
		}
		if ("F".equals(isConfirmOrReject)) {
			for(int i=0;i<ids.length;i++){
				dao.updateProductUpdateIsbuy("2",context.getLoginUserId(),context.getLoginUserName(),new framework.core.DateUtil().getFullString(),ids[i]);
			}
			aForm.getRequest().setAttribute("SUCCESSMSG", "审批不通过执行成功");
		}
		
		aForm.getRequest().setAttribute("action","A190014.do?type="+type);					
		return GSBaseConstants.FORWARD_SUCCESS;

	}
}
